﻿<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib prefix="c"
uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
  <head>
    <title>Title</title>
    <link rel="stylesheet" href="${ctx}/common/plugins/layuiadmin/style/admin.css" media="all" />
    <link rel="stylesheet" href="${ctx}/common/plugins/layuiadmin/layui/css/layui.css" media="all" />
    <script src="${ctx}/common/plugins/layuiadmin/layui/layui.js"></script>
    <link rel="stylesheet" href="${ctx}/common/common.css" />
    <script src="${ctx}/common/plugins/publicJs/publicJs.js"></script>
    <style>
      .layui-body {
        overflow-y: scroll;
      }
      .layui-input-block .layui-unselect {
        width: 100%;
      }
    </style>
  </head>
  <body>
    <!--主体内容层-->
    <div class="layui-fluid">
      <div class="layui-row layui-col-space15">
        <div class="layui-col-md12 layui-col-space15">
          <form class="layui-form">
            <!--输入框内容盒子-->
            <div class="layui-col-md12">
              <!--输入框-->
              <div class="layui-col-md4">
                <label class="layui-form-label">申请单号</label>
                <div class="layui-input-block">
                  <input
                    type="text"
                    name="code"
                    id="code"
                    required
                    lay-verify="required"
                    placeholder="请输入申请单号"
                    autocomplete="off"
                    class="layui-input"
                  />
                </div>
              </div>
              <!--数字框-->
              <div class="layui-col-md4">
                <label class="layui-form-label">申请人</label>
                <div class="layui-input-block">
                  <input
                    type="text"
                    name="creatorName"
                    id="creatorName"
                    required
                    lay-verify="required"
                    placeholder="请输入申请人"
                    autocomplete="off"
                    class="layui-input"
                  />
                </div>
              </div>

              <!--城市选择通用下拉框-->
              <div class="layui-col-md4">
                <label class="layui-form-label">审批状态</label>
                <div class="layui-input-block">
                  <select name="stat" id="stat">
                    <option value="">请选择</option>
                    <option value="0">待审批</option>
                    <option value="1">通过</option>
                    <option value="2">未通过</option>
                  </select>
                </div>
              </div>

              <!-- 							  			<from class="layui-form">
				<div class="layui-col-md3">
	    	<label class="layui-form-label">溯源类型</label>
			<div class="layui-input-block">
				<select name="traceabilityType" lay-filter="aihao">
					<option value=""></option>

						<option value="1">个体溯源</option>

						<option value="2">批量溯源</option>

				</select>
				<div class="layui-unselect layui-form-select layui-form-selected"><div class="layui-select-title"><input type="text" placeholder="请选择" value="" readonly="" class="layui-input layui-unselect"><i class="layui-edge"></i></div><dl class="layui-anim layui-anim-upbit"><dd lay-value="" class="layui-select-tips">请选择</dd><dd lay-value="1" class="">个体溯源</dd><dd lay-value="2" class="">批量溯源</dd></dl></div>
			</div>
		</div>
		</from>	 -->
            </div>

            <!--通用按钮盒子-->
            <div class="layui-col-md12" style="padding-top: 10px; padding-bottom: 10px">
              <!--通用table表格-->
              <!--          <div class="layui-btn-group demoTable">
                        <button class="layui-btn layui-btn-sm" type="button" data-type="addPerson">
                            <i class="layui-icon">&#xe654;</i>
                        </button>
                        删除
                        <button class="layui-btn layui-btn-sm" type="button" data-type="delPersonSelect">
                            <i class="layui-icon">&#xe640;</i>
                        </button>
                    </div> -->
              <div style="float: right" class="layui-btn-group paramBtn">
                <button data-type="reloadLabel" type="button" class="layui-btn layui-btn-sm layui-btn-danger">
                  查询
                </button>
                <button data-type="resetLabel" type="reset" class="layui-btn layui-btn-sm layui-btn-danger">
                  重置
                </button>
              </div>
            </div>
          </form>

          <table
            class="layui-table"
            id="labelReload"
            lay-data="{ url:'${ctx}/label/findLabelPage', page:true,groups:5}"
            lay-filter="demo"
          >
            <thead>
              <tr>
                <!--  <th lay-data="{type:'checkbox', fixed: 'left'}"></th> -->
                <th lay-data="{field:'e_name',sort:true,width:350}">生产企业</th>
                <th lay-data="{field:'p_name',sort:true }">产品名称</th>
                <th lay-data="{field:'b_code',sort:true}">生产批次</th>
                <!--   <th lay-data="{field:'code',sort:true}">申请单号</th>
                    <th lay-data="{field:'creator_name',sort:true}">申请人</th> -->
                <th lay-data="{field:'create_time',sort:true,templet:'#createTime'}">申请时间</th>
                <th lay-data="{field:'traceability_type',sort:false,toolbar:'#type'}">溯源类型</th>
                <th lay-data="{field:'statl',sort:false}">审批状态</th>
                <!--   <th lay-data="{field:'job',sort:true}">职务</th> -->
                <th lay-data="{field:'stat',toolbar:'#barDemo',width:250}">操作</th>
              </tr>
            </thead>
          </table>
        </div>
      </div>
    </div>
    <script type="text/html" id="type">
      {{# if(d.traceability_type == 1){ }} 个体溯源 {{# } }} {{# if(d.traceability_type == 2){ }} 批量溯源 {{# } }}
    </script>
    <script type="text/html" id="barDemo">
      {{# if(d.stat == 1){ }}
      <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="check">查看标签</a>
      <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="view">查看</a>
      <a class="layui-btn layui-btn-xs" lay-event="exportExcel">导出标签</a>
      {{# } }} {{# if(d.stat == 0){ }}
      <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="view">查看</a>
      {{# } }}
    </script>
    <script id="createTime" type="text/html">
      {{# return layui.getDate(d.create_time, 'yyyy-MM-dd hh:mm:ss');}}
    </script>
  </body>
  <script>
    layui.use("table", function () {
      var loading = layer.msg("数据加载中...");
      var table = layui.table;
      table.render({
        done: function () {
          layer.close(loading);
        },
      });
      //监听filter为demo的table中的工具条
      table.on("tool(demo)", function (obj) {
        var data = obj.data;
        if (obj.event === "view") {
          window.location.href = "${ctx}/label/labelViewPage?labelId=" + obj.data.id;
        }
        if (obj.event === "check") {
          window.location.href = "${ctx}/label/labelCheckPage?labelId=" + obj.data.id;
        }
        if (obj.event === "exportExcel") {
          window.location.href = "${ctx}/label/exportExcel?labelId=" + obj.data.id;
        }
      });

      var $ = layui.$,
        active = {
          reloadLabel: function () {
            //条件查询
            var code = document.getElementById("code").value;
            var creatorName = document.getElementById("creatorName").value;
            var stat = document.getElementById("stat").value;
            table.reload("labelReload", {
              where: {
                code: code,
                creatorName: creatorName,
                stat: stat,
              },
            });
          },
          resetLabel: function () {
            table.reload("labelReload", {
              where: {
                code: "",
                creatorName: "",
                stat: "",
              },
            });
          },
          addPerson: function () {
            window.location.href = "${ctx}/person/personEditPage";
          },
          delPersonSelect: function () {
            var checkStatus = table.checkStatus("labelReload");
            var ids = "";
            var data = checkStatus.data;
            for (var i in data) {
              ids += data[i].id + ",";
            }
            $.post(
              "${ctx}/person/delPersons",
              { personIds: ids },
              function (data) {
                if (data == "success") {
                  layer.alert("删除成功");
                  table.reload("labelReload", {
                    where: {
                      code: "",
                      creatorName: "",
                      stat: "",
                    },
                  });
                } else {
                  layer.alert("删除失败");
                }
              },
              "text"
            );
          },
        };

      $(".demoTable .layui-btn").on("click", function () {
        var type = $(this).data("type");
        active[type] ? active[type].call(this) : "";
      });
      //给按钮绑定active中的方法
      $(".paramBtn .layui-btn").on("click", function () {
        var type = $(this).data("type");
        //查看是active这个json中是否有type这个方法，如果有调用，如果没有不知心；
        active[type] ? active[type].call() : "";
      });
    });
  </script>
</html>
